import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xiaotutu
 * Date: 2023-09-04
 * Time: 14:49
 */
public class Test {

    public static void bubbleSort(int[] array) {
        for (int i = 0; i < array.length-1; i++) {
            //趟数
            boolean flag = false;
            for (int j = 0; j < array.length-1-i; j++) {
                //比较次数
                if(array[j] > array[j+1]) {
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    flag = true;
                }
            }
            if(false == flag) {
                break;
            }
        }
    }

    public static void main(String[] args) {
        //冒泡排序
        int[] array = new int[]{9,8,7,6,5,4,3,2,1,0};
        //bubbleSort(array);
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
    }
    public static void func1(int[] array) {
        array = new int[]{4,5,6};
    }
    public static int[] func2(int[] array) {
        int a = 10;
        int b = 20;
        int c = 30;
        return new int[]{a,b,c};
    }

    public static String myToString(int[] array) {
        if(array == null) {
            return null;
        }
        String ret = "[";
        for (int i = 0; i < 5; i++) {
            ret += array[i];
            if(i < array.length-1) {
                ret += ",";
            }
        }
        return ret += "]";
    }

    public static void main5(String[] args) {
        /*int a = 3;
        int[] array = new int[a];
        System.out.println("使用前：" + Arrays.toString(array));
        func1(array);
        System.out.println("使用后：" + Arrays.toString(array));
        System.out.println(Arrays.toString(array));
        int[] ret = func2(array);
        System.out.println(Arrays.toString(ret));*/
        int[] array = {1,2,3,4,5};
        String ret =myToString(array);
        System.out.println(ret);
    }




    /**
     *
     * @param args
     */
    public static void main4(String[] args) {
        int[] array = new int[]{1,2,3,4,5};
        //System.out.println(Arrays.toString(array));
        System.out.println(array);
    }
    public static int fib1(int n) {
        int a = 0;
        int b = 1;
        int c = 1;
        for (int i = 2; i < n; i++) {
            b = c;
            a = b;
            c = a+b;
        }
        return c;
    }

    public static void main3(String[] args) {
        int[] array;
        array = new int[10];

        //迭代实现
        System.out.println("请输入数字：");
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(fib(n));
    }

    public static int fib(int n) {
        if(n <= 1) {
            return n;
        }else {
            return fib(n-1) + fib(n-2);
        }
    }
    public static void main2(String[] args) {
        //求斐波那契数列的第n项。(递归实现)
        System.out.println("请输入数字：");
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(fib(n));
    }

    public static  int add(int x, int y) {
        return x + y;
    }

    public static double add(double x,double y) {
        return x + y;
    }

    public static void main1(String[] args) {
        System.out.println(add(1, 2));
        System.out.println(add(1.5, 2.5));
    }
}


